//创建头像和昵称随机数组
let arr = ["../img/head01.jpg", "../img/head02.jpg", "../img/head03.jpg"]
let arr1 = ["时尚伊人", "六月奇迹", "松松"]
//获得头像昵称
function getHead() {
    let index = Math.floor(Math.random() * arr.length)
    console.log(index);
    return arr[index]
}

//获得内容
function getMsg() {
    let v = document.querySelector(".chatText").value
    if (v.trim().length === 0) {
        return
    }
    //创建li保存数据
    let li = document.createElement('li')
    let img = getHead()
    //获得昵称
    let j = arr.indexOf(img)
    console.log(j);
    let name = arr1[j]
    //拼接字符串到html
    let str = `
   <div class="img-wrap"><img src="${img}" alt="" class="comment-img">
   </div>
   <!--中间信息-->
   <div class="msg">
       <p>${name}</p>
       <p class="content">${v}</p>
   </div>`
    li.innerHTML = str
    let ul = document.querySelector(".chatBody>ul")
    ul.appendChild(li)

    return li
}

// function sss() {
//     let send = document.querySelector("#send")

//     send.onclick = function () {
//         getMsg()
//     }
// }
// sss()
$(function () {
    $("#send").click(function () {
        getMsg()
        $(".content").addClass("change")
    })


})
